package com.yangrui.app.controller;

import com.yangrui.app.entity.Video;
import com.yangrui.app.service.VideoService;
import com.yangrui.app.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/video")
@Api(value = "视频接口", tags = "视频接口")
public class VideoController {

    @Autowired
    private VideoService videoService;

    @GetMapping("/list")
    @ApiOperation(value = "获取视频列表", notes = "不需要token")
    public Result list() {
        List<Video> list = videoService.list();
        return list!=null? Result.ok(list):Result.fail();
    }

    @GetMapping("/select-detail-by-id")
    @ApiOperation(value = "获取视频详情", notes = "不需要token")
    public Result selectDetailById(@RequestParam Integer id) {
        Video video = videoService.selectDetailById(id);
        return video.getId() > 0 ? Result.ok(video):Result.fail(video.getId(),video.getTitle());
    }
}
